package com.seal.yoyoshop.web;

import com.seal.yoyoshop.bin.Goods;
import com.seal.yoyoshop.bin.Type;
import com.seal.yoyoshop.service.GoodsService;
import com.seal.yoyoshop.service.TypeService;
import com.seal.yoyoshop.service.impl.GoodsServiceImpl;
import com.seal.yoyoshop.service.impl.TypeServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DetailServlet", value = "/index/detail")
public class DetailServlet extends HttpServlet {

    private TypeService typeService = new TypeServiceImpl();
    private GoodsService goodsService = new GoodsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        获取前端发来的数据
        String goodIdstr = request.getParameter("goodid");
        int goodId = goodIdstr == null ? 1 : Integer.parseInt(goodIdstr);
//        导航栏
        List<Type> typeList = typeService.getTypeList();
        request.setAttribute("typeList",typeList);
//        找数据
        Goods good = goodsService.getGoodById(goodId);
        request.setAttribute("good",good);
        request.getRequestDispatcher("/index/detail.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
